<template>
  <div class="card-list">
    <div class="v-card" v-for="(item, index) in videoList" :key="index" @click="selectRecommendItem(item.vid)">
      <div class="card">
        <el-image class="cover" :src="item.img | coverUrl" lazy></el-image>
        <div class="count">
         <p class="title">{{ item.title }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { coverUrl } from "@/utils/url";
import { getRecommendList } from "@/api/video";
export default {
  props: {},
  data() {
    return {
      videoList: [],
      page: 1,
      page_size: 10,
      flag: true, //视频在第一页
    };
  },
  methods: {
    selectItem(item) {
      this.$router.push({ name: "video", params: { vid: item.vid } });
    },
    _getRecommendList() {
      getRecommendList(this.page, this.page_size).then(res => {
        if (res.data.code === 200) {
          if (this.flag) {
            this.videoList = res.data.data.data;
            this.flag = !this.flag;
          } else {
            var newList = res.data.data.data;
            if (newList.length == 0) {
              this.$message.info("没有更多了");
            } else {
              this.videoList = this.videoList.concat(newList);
            }
          }
        }
      });
    },
    selectRecommendItem(vid) {
      this.$router.push({ name: "video", params: { vid: vid } });
    },
    getMore() {
      this.page++;
      this._getRecommendList();
    },
  },
  created() {
    this._getRecommendList();
  },
  filters: {
    coverUrl(name) {
      return coverUrl(name);
    },
  },
};
</script>

<style>
.card-list {
  display: flex;
  flex-wrap: wrap;
}

.v-card {
  display: inline-block;
  width: 20%;
  height: 230px;
  padding: 8px 5px;
  box-sizing: border-box;
}

.card {
  position: relative;
  overflow: hidden;
  border-radius: 3px;
}

.cover {
  top: 0;
  left: 0;
  width: 100%;
  height: 200px;
}

.count {
  display: flex;
  justify-content: space-between;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 5px 6px;
  height: 80px;
  box-sizing: border-box;
  color: #ffffff;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.85), transparent);
}

.title {
  font-size: 13px;
  line-height: 16px;
  margin-top: 40px;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
</style>